<template>
	<view>
		<!-- 搜索 -->
		<view class="seacch">
			<my-search @click="handoSeacrh"></my-search>
		</view>
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<navigator class="swipre-item" :url="'/subpkg/goods_detail/goods_detail?id=' + item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航 -->
		<view class="zhobu">
			<view class="fenl">
				<image class="baumg" :src="item.image_src" v-for="(item,index) in navList" :key="index" @click="navClickhado(item.name)"></image>
			</view>
		</view>
		<!-- 广告楼层 -->
		<view class="foolt">
			<view class="foolt-list" v-for="(item,index) in floorList" :key="index">
				<image class="foolt-tito" :src="item.floor_title.image_src"/></image>
				<view class="foolt-box">
					<view class="foolt-left">
						<navigator :url="item.product_list[0].url">
							<image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
						</navigator>
					</view>
					<view class="foolt-right">
						<navigator :url="itemm.url" v-for="(itemm,index) in item.product_list.slice(1,5)" :key="index">
							<image :style="{width:itemm.image_width + 'rpx'}" :src="itemm.image_src" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				//轮播图
				swiperList:[],
				//分类导航
				navList:[],
				//楼层数据
				floorList:[]
			};
		},
		onLoad(){
			//获取首页数据数据
			this.getSwiperList()
			//获取分类导航
			this.getnavList()
			//获取楼层数据
			this.getfloorList()
		},
		methods:{
			//获取轮播图
			async getSwiperList(){
				const { data:res } = await uni.$http.get('/home/swiperdata')
				if(res.meta.status === 200){
					this.swiperList = res.message
				}else{
					uni.$showMsg()
				}
			},
			async getnavList(){
				const { data:res } = await uni.$http.get('/home/catitems')
				if(res.meta.status === 200){
					this.navList = res.message
				}else{
					uni.$showMsg()
				}
			},
			//分类点击事件
			navClickhado(name){
				if(name=="分类"){
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}else if(name=="秒杀拍"){
					console.log('秒杀拍')
				}else if(name=="超市购"){
					console.log('超市购')
				}else{
					console.log('母婴品')
				}
			},
			//获取楼层数据
			async getfloorList(){
			 const { data:res } = await uni.$http.get('/home/floordata')
			 if(res.meta.status === 200){
				res.message.map(item=>{
					item.product_list.map(itemm=>{
						itemm.url = '/subpkg/goods_list/goods_list?' + itemm.navigator_url.split('?')[1]
					})
				})
			 	this.floorList = res.message
			 }else{
			 	uni.$showMsg()
			 }
			},
			//搜索点击事件
			handoSeacrh(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
			//点击轮播跳转至该详情页uni.navigateTo
			// handoimg(id){
			// 	uni.navigateTo({url:'/subpkg/goods_detail/goods_detail?id=' + id})
			// }
		}
	}
</script>

<style lang="scss" scoped>
.seacch{
	position: sticky;
	top: 0;
	z-index: 999;
}
swiper{
	height: 330rpx;
	.swipre-item{
		width: 100%;
		height: 100%;
		image{
			width: 100%;
			height: 100%;
		}
	}
}
.zhobu{
	border-top: 1px solid #999999;
	padding-top: 10rpx;
	width: 100%;
	.fenl{
		padding: 10rpx;
		display: flex;
		justify-content: space-between;
		.baumg{
			width: 128rpx;
			height: 140rpx;
		}
	}
}
.foolt{
	margin-top: 20rpx;
	.foolt-list{
		margin-bottom: 5rpx;
		.foolt-tito{
			width: 100%;
			height: 60rpx;
		}
		.foolt-box{
			display: flex;
			padding-left: 10rpx;
			.foolt-right{
				display: flex;
				flex-wrap: wrap;
				justify-content: space-around;
			}
		}
	}
}
</style>
